package com.yxkj.syh.app.huarong.activities.creat.address;

import android.os.Bundle;
import android.text.TextUtils;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.syh.app.basic.base.BaseActivity;
import com.yxkj.syh.app.huarong.BR;
import com.yxkj.syh.app.huarong.R;
import com.yxkj.syh.app.huarong.constants.ArouterPath;
import com.yxkj.syh.app.huarong.databinding.ActivityFromAddressesBinding;

/**
 * 发货地址 UserMainInfo
 */
@Route(path = ArouterPath.FROM_ADDRESSES_ACTIVITY)
public class FromAddressesActivity extends BaseActivity<ActivityFromAddressesBinding, FromAddressesVM> {
    @Override
    protected int getContentLayout() {
        return R.layout.activity_from_addresses;
    }

    @Override
    protected int getViewModelId() {
        return BR.fromAddressesVM;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mVDBinding.titleView.setLeftOnClickListener(v -> {
            finish();
        });
    }

    @Override
    protected void initObservers() {
        super.initObservers();
        mViewModel.mldUserMainInfo.observe(this, userMainInfo -> {
            if (userMainInfo == null || TextUtils.isEmpty(userMainInfo.getArea())) {
                mVDBinding.titleView.setRightText("添加发货地址");
                mVDBinding.titleView.setRightOnClickListener(v -> {

                });
            } else {
                mVDBinding.titleView.setRightText("");
                mViewModel.ofHasAddress.set(true);
                mViewModel.ofName.set(userMainInfo.getLinkman());
                mViewModel.ofAddress.set(userMainInfo.getArea() + userMainInfo.getAddress());
            }
        });
    }
}
